s = input()
x1 = int(s[0])
x2 =int (s[1])
x3 = int(s[2])
x4 = int(s[3])
x11 = int(s[:2])
x12 = int(s[1:3])
x13 = int(s[2:])
x111 = int(s[:3])
x112 = int(s[1:])
x = int(s)
if x<1000:
    print(0)
else:
    a = []
    k = 0
    for i1 in range(1,x+1):
        if x%i1==0:
            k+=1
    if k==2:
        a.append(x)
    k=0 
    for i in range(1,x1+1):
        if x1%i==0:
            k+=1
    if k==2:
        a.append(x1)
    k=0            
    for i2 in range(1,x2+1):
        if x2%i2==0:
            k+=1
    if k==2:
        a.append(x2)
    k=0
    for i3 in range(1,x3+1):
        if x3%i3==0:
            k+=1
    if k==2:
        a.append(x3)
    k=0
    for i4 in range(1,x4+1):
        if x4%i4==0:
            k+=1
    if k==2:
        a.append(x4)
    k=0       
    for i5 in range(1,x11+1):
        if x11%i5==0:
            k+=1
    if k==2:
        a.append(x11)
    k=0

    for i6 in range(1,x12+1):
        if x12%i6==0:
            k+=1
    if k==2:
        a.append(x12)
    k=0  
    for i7 in range(1,x13+1):
        if x13%i7==0:
            k+=1
    if k==2:
        a.append(x13)
    k=0
    for i8 in range(1,x111+1):
        if x111%i8==0:
            k+=1
    if k==2:
        a.append(x111)
    k=0            
    for i9 in range(1,x112+1):
        if x112%i9==0:
            k+=1
    if k==2:
        a.append(x112)
    k=0
    if len(a)==0:
        print(0)
    else:
        print(max(a))
